package logic

import (
	"baidu/models/mysql"
	"context"

	"baidu/baidurpc/baidurpc"
	"baidu/baidurpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentListLogic {
	return &CommentListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 评论展示
func (l *CommentListLogic) CommentList(in *baidurpc.CommentListRequest) (*baidurpc.CommentListResponse, error) {
	// todo: add your logic here and delete this line

	var comment []mysql.Comment
	mysql.DB.Debug().Find(&comment)

	var commentList []*baidurpc.CommentList
	for _, m := range comment {
		list := baidurpc.CommentList{
			Context: m.Context,
			Publish: m.Publish,
		}
		commentList = append(commentList, &list)
	}

	return &baidurpc.CommentListResponse{
		List: commentList,
	}, nil
}
